import axios from 'axios'
import Vue from 'vue'
import {hideLoading, showLoading} from "@/utils/loading";

const request = axios.create({
    baseURL: 'http://localhost:8081'
});


// 请求拦截器
request.interceptors.request.use(function (config) {
    console.log(config.url);
    showLoading()
    //发送请求前做什么
    return config;
}, function (error) {
    //请求错误做什么
    return Promise.reject(error)
});
//响应拦截器
request.interceptors.response.use(function (response) {
    if (response.data.code === "500") {
        Vue.prototype.$message.error(response.data.msg);
    }
    console.log(response)
    hideLoading()
    return response;
}, function (error) {
    console.log(error);
    if(error.response.status===401){
        Vue.prototype.$message.error('未登录');
        return error.response
    }

    return Promise.reject(error)
})

export default request;
